﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Kugar.Core.ExtMethod;
using Kugar.Core.Web;
using Kugar.Tools.IM.Tencent.ServerSDK;
using Kugar.Tools.IM.Tencent.ServerSDK.Enums;

namespace Kugar.Tools.IM.Tencent.ServerTest.Controllers
{
    public class UserController : Controller
    {
        //private static TencentIM _im = null;
        private static TencentIMApi _api = null;
        static UserController()
        {
            var privatekey =System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("/group_private_key.pem"),Encoding.Default);

            //_im=new TencentIM();

            _api = new TencentIMApi(1400071705, "admin", privatekey, 22208);
        }

        // GET: User
        public ActionResult Index()
        {
            //_api.GroupApi.GetGroupInfoByID("Group_5a9d3a8aa2e3da0b54b34844");

            //ViewBag.AccountID=Request.getstr
            var accountID = Request.GetString("AccountID");

            ViewBag.AccountID = accountID;
            ViewBag.UserSig = _api.AccountApi.GetUserSigByAccountID(accountID).ReturnData;
            //ViewBag.SelToID = accountID.If(x => x == "test1", "test2").Elseif(x => x == "test2", "test1").Result;
            ViewBag.SelToID = "Group_5a9d3a8aa2e3da0b54b34844";

            return View();
        }

        public ActionResult CreateGroup()
        {
            _api.AccountApi.Import(new[]
                                   {
                                       "Employee_5a0d3184785a432888802982",
                                       "Parent_5a1d1a6d21ee32655004634d"

                                   });

            _api.GroupApi.Create(GroupTypeEnum.Public, "黄老的聊天群",
                "Parent_5a1d1a6d21ee32655004634d", new[]
                                            {
                                                "Employee_5a0d3184785a432888802982",
                                                "Parent_5a1d1a6d21ee32655004634d"

                                            },groupId: "Group_5a1d1a6d21ee32655004634d");

            return Content("创建成功");
        }
    }
}